#ifndef _LOOKAHEADPARSER_H_
#define _LOOKAHEADPARSER_H_

#include "lexer.h"
#include "parser.h"
#include "common.h"

class LookaheadParser : public Parser {
public:
    LookaheadParser(Lexer *input, int k): Parser(input, k) { }

    void list() {
        match(LBRACK);
        elements();
        match(RBRACK);
    }

    void elements() {
        element();
        while (LA(1) == COMMA) {
            match(COMMA);
            element();
        }
    }

    void element() {
        if (LA(1) == NAME && LA(2) == EQUALS) {
            match(NAME);
            match(EQUALS);
            match(NAME);
        }
        else if (LA(1) == NAME)
            match(NAME);
        else if (LA(1) == LBRACK)
            list();
        else {
            string s = "expecting name or list; found ";
            s += LT(1)->text;
            throw Error(s);
        }
    }
};

#endif
